<?php

namespace DebugComponent\Filter;

/**
 * Message filter by message types
 */
class Type implements \DebugComponent\IFilter {

    /**
     * Class constructor
     *
     * @param array $messageTypes
     * @return Type instance
     */
    public function __construct(array $messageTypes) {
        $this->messageTypes = $messageTypes;
    }

    /**
     * Filter message returns true otherwise false
     *
     * @param \DebugComponent\IMessage $message
     * @return boolean
     * @see \DebugCompontnt\IFilter
     */
    public function filter(\DebugComponent\IMessage $message) {
        if ($this->messageTypes === null) {
            return true;
        }

        foreach ($this->messageTypes as $messageType) {
            if ($message instanceof $messageType) {
                return true;
            }
        }

        return false;
    }

    /**
     * @var array $messageTypes
     */
    private $messageTypes;
}